package com.flong.spring;


import com.flong.spring.bean.Student;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
 * @Author:liangjl
 * @Date: 2020/6/8-22:22
 * @Eamil:jilongliang@sina.com
 * @Description:
 * IOC (Inverse of Control ,控制反转）
 * DI (Dependency Injection 依赖注入）
 */
public class SpringClient {

    public static void main(String[] args) {
        //获取资源文件
        Resource resource = new ClassPathResource("applicationContext.xml");

        DefaultListableBeanFactory defaultListableBeanFactory = new DefaultListableBeanFactory();
        //读取器
        BeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(defaultListableBeanFactory);

        beanDefinitionReader.loadBeanDefinitions(resource);

        //方法1、getBean就是xml的id,向下强转
        //Student student = (Student)defaultListableBeanFactory.getBean("student");

        //方法2
        Student student = defaultListableBeanFactory.getBean("student", Student.class);

        System.out.println(student.getUserName() + "--" + student.getAge());


    }


}
